--
-- Author: shunguo.chen
-- Date: 2017-11-24 10:26:43
--
-- BoxItemVo 宝箱奖励vo

local protobuf = require "protobuf"

local fileName = string.getModeName(...)
local ClassRef = class(fileName)

function ClassRef:ctor(data)
    if data then
        self:init(data)
    end
end

-- message LuckItem {
--   Loot loot = 1;
--   LuckItemQuality luckItemQuality = 2;
-- }
function ClassRef:init(data)
    self.itemData = UD:parseLootToBagItem(data.loot)

    if data.luckItemQuality then
        -- 通用的luckbox
        self.quality = protobuf.enum_id("pb_luckbox.LuckItemQuality", data.luckItemQuality or "white") + 1
    else
        -- 不是luckbox，但是想借用luckbox，所以凑出来数据
        if self.itemData.getQuality then
            self.quality = self.itemData:getQuality()
        else
            self.quality = 1
        end

        -- 策划说金币特殊处理为紫色
        if self.itemData.tid == 99 then
            self.quality = 4
        end
    end
end

function ClassRef:initWithBagItem(data)
    self.itemData = data
    if self.itemData.getQuality then
        self.quality = self.itemData:getQuality()
    else
        self.quality = 1
    end

    -- 策划说金币特殊处理为紫色
    if self.itemData.tid == 99 then
        self.quality = 4
    end
end

return ClassRef